//鼠标左键点击
import { Behaviour } from "../engine/Behaviour";
import { BitmapRenderer } from "../engine/BitmapRenderer";
import { Transform } from "../engine/Transform";
import { number } from "../engine/validators/number";
import { createGameObject, getGameObjectById } from "../engine";
import{ objectLift } from "../behaviours/objectLift";
import { Display } from "./Display";
import { MouseControlSystem } from "../engine/systems/MouseControlSystem";
import { display } from "@microsoft/fast-foundation";
import { cookAlert } from "../behaviours/cookAlert";
import { xinagcaiPrefabBehaviour} from "../prefabBehaviours/xinagcaiPrefabBehaviour";
import { onionPrefabBehavior } from "../prefabBehaviours/onionPrefabBehavior";
import { latiaoPrefabBehavior } from "../prefabBehaviours/latiaoPrefabBehavior";
import { sausagePrefabBehavior } from "../prefabBehaviours/sausagePrefabBehavior";
import { ChangeScene } from "./ChangeScene";
import { BillSystem } from "./BillSystem";
import { TextRenderer } from "../engine/TextRenderer";
import { AnimationRenderer } from "../AnimationRenderer";
import { chikenPrefabBehaviour } from "../prefabBehaviours/chikenPrefabBehaviour";
import { baconPrefabBehaviour } from "../prefabBehaviours/baconPrefabBehaviour";
import { suanrongPrefabBehaviour } from "../prefabBehaviours/suanrongPrefabBehaviour";
import { conghuaPrefabBehaviour } from "../prefabBehaviours/conghuaPrefabBehaviour";
import { BitmapWithClipRender } from "../engine/BitmapWithClipRender";
import { sugarPrefabBehaviour } from "../prefabBehaviours/sugarPrefabBehaviour";
import { Audio } from "../engine/Audio";
import { dateStorageInUI } from "./dateStorageInUI";
import { mask } from "./mask";
import { OrderButtonClick } from "./OrderButtonClick";

//设一个全局变量，查看上一个点击的是那个GameObject
let lastClickObject:String
let hasOil = false
let hasSkin = false
let hasCut = false
let hasDone = false
export class LeftMouseClick extends Behaviour{
    private currentSpeed = 0;
    @number()
    speed = 1;
    onionPrefabBinding = new onionPrefabBehavior()
    onion
    
    sausagePrefabBinding = new sausagePrefabBehavior()
    sausage
    xiangcaiPrefabBinding = new xinagcaiPrefabBehaviour()
    xiangcai
    
    putEgg = 0
    putSausage = 0
    putChiken = 0
    putBacon = 0
    putLatiao = 0

    putSugar = 0

    putXiangcai = 0
    putOnion = 0
    putSuanrong = 0
    putConghua = 0

    putBJUT = false
    //教学的判断flag
    firstTeach = 1
    techFlag = 0

    onStart(): void {
       
        //取消上一个点击的高亮和升起
        function cancelOutline(gameObejectid:String){
            console.log(gameObejectid)
            if(gameObejectid === "oil"){
                getGameObjectById('oil').getBehaviour(BitmapRenderer).source = "./assets/images/oil_1.png";
                getGameObjectById('oilLift').getBehaviour(Display).IsActive = false
                getGameObjectById('oilLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "eggBG"){
                getGameObjectById('eggBG').getBehaviour(BitmapRenderer).source = "./assets/images/egg_2.png";
                getGameObjectById('egg').getBehaviour(Display).IsActive = false
                getGameObjectById('egg').getBehaviour(objectLift).flag = 0
                getGameObjectById("shovelPut").getBehaviour(Display).IsActive = false
            }
            if(gameObejectid === "skinBG"){
                console.log("取消面匹")
                getGameObjectById('skinBG').getBehaviour(BitmapRenderer).source = "./assets/images/skin_2.png";
                getGameObjectById('skin').getBehaviour(Display).IsActive = false
                getGameObjectById('skin').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "sausageBG"){
                getGameObjectById('sausageBG').getBehaviour(BitmapRenderer).source = "./assets/images/sausage_2.png";
                getGameObjectById('sausageLift').getBehaviour(Display).IsActive = false
                getGameObjectById('sausageLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "bacon"){
                getGameObjectById('bacon').getBehaviour(BitmapRenderer).source = "./assets/images/bacon_1.png";
                getGameObjectById('baconLift').getBehaviour(Display).IsActive = false
                getGameObjectById('baconLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "chiken"){
                getGameObjectById('chiken').getBehaviour(BitmapRenderer).source = "./assets/images/chicken_1.png";
                getGameObjectById('chikenLift').getBehaviour(Display).IsActive = false
                getGameObjectById('chikenLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "onion"){
                getGameObjectById('onion').getBehaviour(BitmapRenderer).source = "./assets/images/onion_1.png";
                getGameObjectById('onionLift').getBehaviour(Display).IsActive = false
                getGameObjectById('onionLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "xiangcai"){
                getGameObjectById('xiangcai').getBehaviour(BitmapRenderer).source = "./assets/images/green_1.png";
                getGameObjectById('xiangcaiLift').getBehaviour(Display).IsActive = false
                getGameObjectById('xiangcaiLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "conghua"){
                getGameObjectById('conghua').getBehaviour(BitmapRenderer).source = "./assets/images/green_onion_1.png";
                getGameObjectById('conghuaLift').getBehaviour(Display).IsActive = false
                getGameObjectById('conghuaLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "sauce"){
                getGameObjectById('sauce').getBehaviour(BitmapRenderer).source = "./assets/images/sauce_1.png";
                getGameObjectById('sauceLift').getBehaviour(Display).IsActive = false
                getGameObjectById('sauceLift').getBehaviour(objectLift).flag = 0
                getGameObjectById("shuaziPut").getBehaviour(Display).IsActive = false
                
            }
            if(gameObejectid === "vinegar"){
                getGameObjectById('vinegar').getBehaviour(BitmapRenderer).source = "./assets/images/vinegar_1.png";
                getGameObjectById('vinegarLift').getBehaviour(Display).IsActive = false
                getGameObjectById('vinegarLift').getBehaviour(objectLift).flag = 0
                getGameObjectById("vinegarshuaziPut").getBehaviour(Display).IsActive = false
            }
            if(gameObejectid === "sugar"){
                getGameObjectById('sugar').getBehaviour(BitmapRenderer).source = "./assets/images/sugar_1.png";
                getGameObjectById('sugarLift').getBehaviour(Display).IsActive = false
                getGameObjectById('sugarLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "suanrong"){
                getGameObjectById('suanrong').getBehaviour(BitmapRenderer).source = "./assets/images/蒜蓉_.png";
                getGameObjectById('suanrongLift').getBehaviour(Display).IsActive = false
                getGameObjectById('suanrongLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "spicysauce"){
                getGameObjectById('spicysauce').getBehaviour(BitmapRenderer).source = "./assets/images/spicy_sauce_1.png";
                getGameObjectById('spicysauceLift').getBehaviour(Display).IsActive = false
                getGameObjectById('spicysauceLift').getBehaviour(objectLift).flag = 0
                getGameObjectById("spicysauceshuaziPut").getBehaviour(Display).IsActive = false
            }
            if(gameObejectid === "latiao"){
                getGameObjectById('latiao').getBehaviour(BitmapRenderer).source = "./assets/images/spicy_1.png";
                getGameObjectById('latiaoLift').getBehaviour(Display).IsActive = false
                getGameObjectById('latiaoLift').getBehaviour(objectLift).flag = 0
            }
            if(gameObejectid === "shovel"){
                getGameObjectById('shovel').getBehaviour(BitmapRenderer).source = "./assets/images/shovel_2.png";
            }
            if(gameObejectid === "package"){
                getGameObjectById('package').getBehaviour(BitmapRenderer).source = "./assets/images/skinBox_1.png";
            }
            if(gameObejectid === "packageBJUT"){
                getGameObjectById('packageBJUT').getBehaviour(BitmapRenderer).source = "./assets/images/bjut冷面盒_1.png";
            }

        }
        this.gameObject.onClick = (event) => {

            hasDone = false
            //当前点击的GameObject的id
            let money = Number(getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text)
            let money1: string
            //成本
            let cost = Number(getGameObjectById('Text_cost').getBehaviour(TextRenderer).text)
            let cost1: string
            console.log("left "+ this.gameObject.id);
            
            // this.gameObject.active=false;
            if (this.gameObject.id === "oil" ) {
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //点击，换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/oil_light_1.png"; 

                //单独油勺升高
                getGameObjectById('oilLift').getBehaviour(Display).IsActive = true
                getGameObjectById('oilLift').getBehaviour(objectLift).flag = -1;
                this.techFlag = 1
            }
            if (this.gameObject.id === "eggBG" ) {
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //点击，换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/egg_light_1.png";    
                //单独鸡蛋升高
                getGameObjectById('egg').getBehaviour(Display).IsActive = true
                getGameObjectById('egg').getBehaviour(objectLift).flag = 1;
                //打开eggSpread
                getGameObjectById("eggSpread").getBehaviour(Display).IsActive = true
                //提示指向锅中
                // getGameObjectById('hand').getBehaviour(Display).IsActive = false
                // getGameObjectById('handMid').getBehaviour(Display).IsActive = true
                
            }
            
            if(this.gameObject.id === "skinBG"){
                cancelOutline(lastClickObject)
                
                lastClickObject = this.gameObject.id
                console.log("点击Skin,应该高亮！！！");
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/skin_light_1.png";
               
                //单独面皮升起
                getGameObjectById('skin').getBehaviour(Display).IsActive = true                
                getGameObjectById('skin').getBehaviour(objectLift).flag = 2

                //提示跳到锅中间
                // getGameObjectById('hand').getBehaviour(Display).IsActive = false
                // getGameObjectById('handMid').getBehaviour(Display).IsActive = true
                //this.techFlag = 3
            }
            
            if(this.gameObject.id === "onion"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/onion_light_1.png";                
                //单独洋葱升起
                getGameObjectById('onionLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('onionLift').getBehaviour(objectLift).flag = 3            

            }
            if(this.gameObject.id === "suanrong"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/蒜蓉_light_1.png";                
                //单独蒜蓉升起
                getGameObjectById('suanrongLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('suanrongLift').getBehaviour(objectLift).flag = 6            
            }
            if(this.gameObject.id === "conghua"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/green_onion_light_1.png";                
                //单独葱花升起
                console.log("conghuazenmel")
                getGameObjectById('conghuaLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('conghuaLift').getBehaviour(objectLift).flag = 6            
            }
            if(this.gameObject.id === "xiangcai"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/green_light_1.png";
                

                console.log("点击xiangcai,应该高亮！！！");
                //单独香菜升起
                getGameObjectById('xiangcaiLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('xiangcaiLift').getBehaviour(objectLift).flag = 3
                

            }
            if(this.gameObject.id === "sauce"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/sauce_light_1.png";
                
                console.log("点击sauce,应该高亮！！！");
                //单独酱升起
                getGameObjectById('sauceLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('sauceLift').getBehaviour(objectLift).flag = 3
                //刷子到中间
                getGameObjectById("shuaziPut").getBehaviour(Display).IsActive = true

                //打开sauceSpread
                getGameObjectById("sauceSpread").getBehaviour(Display).IsActive = true
                
            }
            if(this.gameObject.id === "vinegar"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/vinegar_light_1.png";             
                console.log("点击sauce,应该高亮！！！");
                //单独醋升起
                getGameObjectById('vinegarLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('vinegarLift').getBehaviour(objectLift).flag = 3
                //刷子到中间
                getGameObjectById("vinegarshuaziPut").getBehaviour(Display).IsActive = true
                //打开vinegarSpread
                getGameObjectById("vinegarSpread").getBehaviour(Display).IsActive = true
            }
            if(this.gameObject.id === "spicysauce"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/spicy_sauce_light_1.png";             
                console.log("点击spicysauce,应该高亮！！！");
                //单独辣酱升起
                getGameObjectById('spicysauceLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('spicysauceLift').getBehaviour(objectLift).flag = 7
                //刷子到中间
                getGameObjectById("spicysauceshuaziPut").getBehaviour(Display).IsActive = true
                //打开spicysauceSpread
                getGameObjectById("spicysauceSpread").getBehaviour(Display).IsActive = true
            }
            if(this.gameObject.id === "sugar"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/sugar_light_1.png";
            
                
                console.log("点击sauce,应该高亮！！！");
                //单独糖升起
                getGameObjectById('sugarLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('sugarLift').getBehaviour(objectLift).flag = 3
                

            }
            if(this.gameObject.id === "sausageBG"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/sausage_light_1.png";
                
                console.log("点击Sausage,应该高亮！！！");
                //单独香肠升起
                getGameObjectById('sausageLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('sausageLift').getBehaviour(objectLift).flag = 4
            }
            if(this.gameObject.id === "bacon"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/bacon_light_1.png";
                console.log("点击bacon,应该高亮！！！");
                //单独培根升起
                getGameObjectById('baconLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('baconLift').getBehaviour(objectLift).flag = 4
            }
            if(this.gameObject.id === "chiken"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/chicken_light_1.png";
                //单独培根升起
                getGameObjectById('chikenLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('chikenLift').getBehaviour(objectLift).flag = 5
            }
            
            if(this.gameObject.id === "latiao"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/spicy_light_1.png";
                console.log("点击latiao,应该高亮！！！");
                //单独辣条升起
                getGameObjectById('latiaoLift').getBehaviour(Display).IsActive = true                
                getGameObjectById('latiaoLift').getBehaviour(objectLift).flag = 4

            }
            if(this.gameObject.id === "shovel"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/shovel_light_1.png";

                console.log("点击shovel,应该高亮！！！");

            }
            if(this.gameObject.id === "package"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/skinBox_light_1.png";
                console.log("点击package,应该高亮！！！");
                
            }
            if(this.gameObject.id === "packageBJUT"){
                cancelOutline(lastClickObject)
                lastClickObject = this.gameObject.id
                //换当前GameObject换成高亮的
                this.gameObject.getBehaviour(BitmapRenderer).source = "./assets/images/bjut冷面盒_light_1.png";
                console.log("点击packageBJUT,应该高亮！！！");
                
            }


            //第二次点锅
            if(this.gameObject.id === "pot" || this.gameObject.id === "skinPut"  || this.gameObject.id === "oilPut"|| this.gameObject.id === "eggPut" || this.gameObject.id === "pack" || this.gameObject.id === "putTiaoliao" ){
                //console.log(lastClickObject)
                console.log("22222")
                console.log(this.gameObject.id)
                if(lastClickObject === "oil"){
                    //先点击的GameObject高亮归位
                    getGameObjectById('oil').getBehaviour(BitmapRenderer).source = "./assets/images/oil_1.png";
                    //hasOil = true
                    if(hasOil === false){
                        hasOil = true
                        //放油
                        getGameObjectById("oilPut").getBehaviour(Display).IsActive = true
                        getGameObjectById("oilSound").getBehaviour(Audio).Play()
                        //扣钱 
                        money -= 0.1
                        money1 = money.toFixed(2)
                        getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                        //成本+：原料成本
                        cost += 0.1
                        cost1 = cost.toFixed(2)
                        getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                        //提示跳到面皮
                        this.techFlag = 2
                    }
                    else{
                        //错误提示:已经放过油了
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 1;

                    }
                }

                else if(lastClickObject === "skinBG"){
                    //先点击的GameObject高亮归位
                    getGameObjectById('skinBG').getBehaviour(BitmapRenderer).source = "./assets/images/skin_2.png";
                    if(hasSkin === false){
                        if(hasOil === true){
                            hasSkin = true;
                            //放面皮
                            getGameObjectById("skinPut").getBehaviour(Transform).x = 360
                            getGameObjectById("skinPut").getBehaviour(Transform).y = 260
                            getGameObjectById("skinPut").getBehaviour(Display).IsActive = true
                            //油zila的动画
                            getGameObjectById("oilAnimation").getBehaviour(Display).IsActive = true
                            getGameObjectById("zilaSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 0.2
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            
                            //成本+：原料成本
                            cost += 0.2
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;

                            //提示跳到鸡蛋
                            // getGameObjectById('hand').getBehaviour(Display).IsActive = true
                            // getGameObjectById('handMid').getBehaviour(Display).IsActive = false
                            this.techFlag = 3

                        }else{
                            //错误提示：还没放油
                            getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 2;
                            
                        }
                        
                    }else{
                       //alert("放了面皮")
                    }
                    
                }

                else if(lastClickObject === "eggBG" ){
                    //将点击的GameObject高亮归位
                    getGameObjectById('eggBG').getBehaviour(BitmapRenderer).source = "./assets/images/egg_2.png";
                    if(hasOil && hasSkin && hasDone === false){
                        //放一个鸡蛋壳裂开的动画，停住在最后一帧
                        getGameObjectById("eggPut").getBehaviour(Transform).x = 340
                        getGameObjectById("eggPut").getBehaviour(Transform).y = 210
                        getGameObjectById("eggPut").getBehaviour(Display).IsActive = true
                        getGameObjectById("keeggSound").getBehaviour(Audio).Play()
                        //铲儿
                        getGameObjectById("shovelPut").getBehaviour(Display).IsActive = true
                        
                        //扣钱 
                        money -= 1
                        getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(money);
                        //成本+：原料成本
                        cost += 1
                        getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                        //存放的原料--传给UI--与订单对比
                        //this.putEgg = 1
                        this.putEgg ++
                        getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putEgg =this.putEgg
                        
                        //提示跳到酱
                        // getGameObjectById('hand').getBehaviour(Display).IsActive = true
                        // getGameObjectById('handMid').getBehaviour(Display).IsActive = false
                        this.techFlag = 4
                        setTimeout(() => {
                            console.log("等会")
                            getGameObjectById('handMove').getBehaviour(Display).IsActive = false
                            this.techFlag = 5
                        }, 5000);
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }
                    
                }
                else if(lastClickObject === "sausageBG"){
                    //将点击的GameObject高亮归位
                    getGameObjectById('sausageBG').getBehaviour(BitmapRenderer).source = "./assets/images/sausage_2.png";
                    if(hasOil && hasSkin && hasDone === false){
                        //放香肠
                       if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                       //const sausagePrefabBinding = new sausagePrefabBehavior()
                            this.sausage = this.gameObject.engine.createNewPrefab(this.sausagePrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(this.sausage)
                            const sausageTransform = this.sausage.getBehaviour(Transform);
                            sausageTransform.x = event.posX-400;
                            sausageTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 2
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(money);
                            //成本+：原料成本
                            cost += 2
                            cost1 = cost.toFixed(2)
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            
                            //存放的原料--传给UI--与订单对比
                            this.putSausage = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putsausage =this.putSausage
                            this.techFlag = 7
                            }
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }    
                }
                else if(lastClickObject === "bacon"){
                    //将点击的GameObject高亮归位
                    getGameObjectById('bacon').getBehaviour(BitmapRenderer).source = "./assets/images/bacon_1.png";
                    if(hasOil && hasSkin && hasDone === false){
                        //放培根
                       if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                       const baconPrefabBinding = new baconPrefabBehaviour()
                       //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                       const bacon = this.gameObject.engine.createNewPrefab(baconPrefabBinding)
                       getGameObjectById("putTiaoliao").addChild(bacon)
                       const baconTransform = bacon.getBehaviour(Transform);
                       baconTransform.x = event.posX-400;
                       baconTransform.y = event.posY-300;
                       getGameObjectById("putSound").getBehaviour(Audio).Play()
                       //扣钱 
                       money -= 2
                       money1 = money.toFixed(2)
                       getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                       //getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(money);
                       //成本+：原料成本
                       cost += 2
                       cost1 = cost.toFixed(2)
                       getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                       //getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                       //存放的原料--传给UI--与订单对比
                       this.putBacon = 1
                       getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putbacon =this.putBacon
                       }
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }    
                }
                else if(lastClickObject === "chiken"){
                    //将点击的GameObject高亮归位
                    getGameObjectById('chiken').getBehaviour(BitmapRenderer).source = "./assets/images/chicken_1.png";
                    if(hasOil && hasSkin && hasDone === false){
                        //放鸡肉
                       if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                       const chikenPrefabBinding = new chikenPrefabBehaviour()
                       //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                       const chiken = this.gameObject.engine.createNewPrefab(chikenPrefabBinding)
                       getGameObjectById("putTiaoliao").addChild(chiken)
                       const chikenTransform = chiken.getBehaviour(Transform);
                       chikenTransform.x = event.posX-400;
                       chikenTransform.y = event.posY-300;
                       getGameObjectById("putSound").getBehaviour(Audio).Play()
                       //扣钱 
                       money -= 2
                       money1 = money.toFixed(2)
                       getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                       //成本+：原料成本
                       cost += 2
                       cost1 = cost.toFixed(2)
                       getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                       //存放的原料--传给UI--与订单对比
                       this.putChiken = 1
                       getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putchiken =this.putChiken
                       }
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }    
                }
                else if(lastClickObject === "onion" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('onion').getBehaviour(BitmapRenderer).source = "./assets/images/onion_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                       //放洋葱
                       if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                    //    const onionPrefabBinding = new onionPrefabBehavior()
                    //    const onion = this.gameObject.engine.createNewPrefab(onionPrefabBinding)
                            
                            this.onion = this.gameObject.engine.createNewPrefab(this.onionPrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(this.onion)
                            const onionTransform = this.onion.getBehaviour(Transform);
                            onionTransform.x = event.posX-400;
                            onionTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 0.1
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.1
                            //成本+：原料成本
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //存放的原料--传给UI--与订单对比
                            this.putOnion = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putonion =this.putOnion
                            }
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "xiangcai" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('xiangcai').getBehaviour(BitmapRenderer).source = "./assets/images/green_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        //放香菜
                        //判断鼠标在面皮区域内
                        if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                            //const xiangcaiPrefabBinding = new xinagcaiPrefabBehaviour()
                            //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                            this.xiangcai = this.gameObject.engine.createNewPrefab(this.xiangcaiPrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(this.xiangcai)
                            const xiangcaiTransform = this.xiangcai.getBehaviour(Transform);
                            xiangcaiTransform.x = event.posX-400;
                            xiangcaiTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 0.1
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.1
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //存放的原料--传给UI--与订单对比
                            this.putXiangcai = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putxiangcai =this.putXiangcai
                        }
                        
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "suanrong" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('suanrong').getBehaviour(BitmapRenderer).source = "./assets/images/蒜蓉_.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        //放蒜蓉
                        //判断鼠标在面皮区域内
                        if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                            const suanrongPrefabBinding = new suanrongPrefabBehaviour()
                            //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                            const suanrong = this.gameObject.engine.createNewPrefab(suanrongPrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(suanrong)
                            const suanrongTransform = suanrong.getBehaviour(Transform);
                            suanrongTransform.x = event.posX-400;
                            suanrongTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 0.1
                            money1 = money.toFixed(2)
                            //getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(money);
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.1
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //存放的原料--传给UI--与订单对比
                            this.putSuanrong = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putsuanrong =this.putSuanrong
                        }
                        
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "conghua" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('conghua').getBehaviour(BitmapRenderer).source = "./assets/images/green_onion_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        //放葱花
                        //判断鼠标在面皮区域内
                        if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                            const conghuaPrefabBinding = new conghuaPrefabBehaviour()
                            //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                            const conghua = this.gameObject.engine.createNewPrefab(conghuaPrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(conghua)
                            const conghuaTransform = conghua.getBehaviour(Transform);
                            conghuaTransform.x = event.posX-400;
                            conghuaTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 0.1
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.1
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //存放的原料--传给UI--与订单对比
                            this.putConghua = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putconghua =this.putConghua
                        }                        
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "sugar" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('sugar').getBehaviour(BitmapRenderer).source = "./assets/images/sugar_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        //放糖
                        //判断鼠标在面皮区域内
                        if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                            const sugarPrefabBinding = new sugarPrefabBehaviour()
                            //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                            const sugar = this.gameObject.engine.createNewPrefab(sugarPrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(sugar)
                            const sugarTransform = sugar.getBehaviour(Transform);
                            sugarTransform.x = event.posX-400;
                            sugarTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 0.1
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.1
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //存放的原料--传给UI--与订单对比
                            this.putSugar = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putsugar =this.putSugar
                            this.techFlag = 6
                        }                        
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "sauce" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('sauce').getBehaviour(BitmapRenderer).source = "./assets/images/sauce_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        //getGameObjectById('shuaziPut').getBehaviour(Display).IsActive = true
                        console.log("放原味酱")
                        
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }
                }
                else if(lastClickObject === "vinegar" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('vinegar').getBehaviour(BitmapRenderer).source = "./assets/images/vinegar_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        console.log("放醋")
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "spicysauce" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('spicysauce').getBehaviour(BitmapRenderer).source = "./assets/images/spicy_sauce_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        console.log("放辣酱")
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "latiao" ){
                    //先点击的GameObject高亮归位
                    getGameObjectById('latiao').getBehaviour(BitmapRenderer).source = "./assets/images/spicy_1.png";
                    
                    if(hasOil && hasSkin && hasDone === false){
                        if(event.posX < 482 && event.posX > 395 && event.posY > 300 && event.posY < 445){
                            const latiaoPrefabBinding = new latiaoPrefabBehavior()
                            //xiangcaiPrefabBinding.size = Math.floor(Math.random() * 30)
                            const latiao = this.gameObject.engine.createNewPrefab(latiaoPrefabBinding)
                            getGameObjectById("putTiaoliao").addChild(latiao)
                            const latiaoTransform = latiao.getBehaviour(Transform);
                            latiaoTransform.x = event.posX-400;
                            latiaoTransform.y = event.posY-300;
                            getGameObjectById("putSound").getBehaviour(Audio).Play()
                            //扣钱 
                            money -= 1
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=String(money);
                            //成本+：原料成本
                            cost += 1
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=String(cost);
                            //存放的原料--传给UI--与订单对比
                            this.putLatiao = 1
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putlatiao =this.putLatiao
                        }
                        
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }

                }
                else if(lastClickObject === "shovel" ){
                    //将点击的GameObject高亮归位
                    getGameObjectById('shovel').getBehaviour(BitmapRenderer).source = "./assets/images/shovel_2.png";
                    if(hasOil && hasSkin){
                        hasCut = true
                        //折、切动画
                        getGameObjectById("pack").getBehaviour(Display).IsActive = true
                        //把原有的给隐藏
                        getGameObjectById("putTiaoliao").removeChildren();     
                        //清空
                        getGameObjectById("eggSpread").getBehaviour(BitmapWithClipRender).clips = []
                        getGameObjectById("sauceSpread").getBehaviour(BitmapWithClipRender).clips = [] 
                        getGameObjectById("vinegarSpread").getBehaviour(BitmapWithClipRender).clips = []
                        getGameObjectById("spicysauceSpread").getBehaviour(BitmapWithClipRender).clips = []

                        getGameObjectById("eggSpread").getBehaviour(Display).IsActive = false
                        getGameObjectById("sauceSpread").getBehaviour(Display).IsActive = false
                        getGameObjectById("vinegarSpread").getBehaviour(Display).IsActive = false
                        getGameObjectById("spicysauceSpread").getBehaviour(Display).IsActive = false
                        
                        getGameObjectById("skinPut").getBehaviour(Display).IsActive = false
                        console.log(getGameObjectById("skinPut").getBehaviour(Display).IsActive)
                        getGameObjectById("eggPut").getBehaviour(Display).IsActive = false
                        getGameObjectById("oilPut").getBehaviour(Display).IsActive = false
                        getGameObjectById("oilAnimation").getBehaviour(Display).IsActive = false
                        //把循环的声音关上
                        getGameObjectById("zilaSound").getBehaviour(Audio).Pause()
                        console.log("折、切")
                        console.log(getGameObjectById('pack').getBehaviour(AnimationRenderer).currentFrame)
                        setTimeout(() => {
                            this.techFlag = 8
                        }, 2300);
                            
                        
                        
                        hasDone = true
                    }
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }    
                }
                else if(lastClickObject === "package" ){
                    //将点击的GameObject高亮归位
                    getGameObjectById('package').getBehaviour(BitmapRenderer).source = "./assets/images/skinBox_1.png";
                    if(hasOil && hasSkin){
                        if(hasCut === true){
                            console.log("fullpackage")
                            getGameObjectById("pack").getBehaviour(Display).IsActive = false
                            
                            getGameObjectById("fullpackage").getBehaviour(Display).IsActive = true
                            //扣钱：右上角ui 
                            money -= 0.5
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.5
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //把参数设回去,动画也设回第0帧
                            hasCut = false
                            hasOil = false
                            hasSkin = false
                            getGameObjectById('eggPut').getBehaviour(AnimationRenderer).currentFrame = 0;
                            getGameObjectById('oilPut').getBehaviour(AnimationRenderer).currentFrame = 0;
                            getGameObjectById('pack').getBehaviour(AnimationRenderer).currentFrame = 0;
                            
                            //把提示消掉再也不出现
                            getGameObjectById('hand').getBehaviour(Display).IsActive = false

                            
                        }else{
                            //错误提示：还没切呢
                            getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 4;
                        }
                    }
                    
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }    
                }
                else if(lastClickObject === "packageBJUT" ){
                    //将点击的GameObject高亮归位
                    getGameObjectById('package').getBehaviour(BitmapRenderer).source = "./assets/images/bjut冷面盒_1.png";
                    if(hasOil && hasSkin){
                        if(hasCut === true){
                            console.log("fullpackage")
                            getGameObjectById("pack").getBehaviour(Display).IsActive = false
                            
                            getGameObjectById("fullpackageBJUT").getBehaviour(Display).IsActive = true
                            //扣钱：右上角ui 
                            money -= 0.5
                            money1 = money.toFixed(2)
                            getGameObjectById('UI_money_text').getBehaviour(TextRenderer).text=money1;
                            //成本+：原料成本
                            cost += 0.5
                            cost1 = cost.toFixed(2)
                            getGameObjectById('Text_cost').getBehaviour(TextRenderer).text=cost1;
                            //把参数设回去,动画也设回第0帧
                            hasCut = false
                            hasOil = false
                            hasSkin = false
                            getGameObjectById('eggPut').getBehaviour(AnimationRenderer).currentFrame = 0;
                            getGameObjectById('oilPut').getBehaviour(AnimationRenderer).currentFrame = 0;
                            getGameObjectById('pack').getBehaviour(AnimationRenderer).currentFrame = 0;
                            
                            this.putBJUT = true
                            getGameObjectById("dateStorage").getBehaviour(dateStorageInUI).putBJUT =this.putBJUT
                            //把提示消掉再也不出现
                            getGameObjectById('hand').getBehaviour(Display).IsActive = false

                            
                        }else{
                            //错误提示：还没切呢
                            getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 4;
                        }
                    }
                    
                    else{
                        //错误提示：不能放该物品
                        getGameObjectById('alert').getBehaviour(cookAlert). alertFlag = 3;
                    }    
                }
                
            }
        };
    }
    onUpdate(){
        //跳到锅中间
        if(this.techFlag === 1){
            getGameObjectById('hand').getBehaviour(Transform).x = 400
            getGameObjectById('hand').getBehaviour(Transform).y = 400

        }
        if(this.techFlag === 2){
            getGameObjectById('hand').getBehaviour(Transform).x = 200
            getGameObjectById('hand').getBehaviour(Transform).y = 450
        }
        //鸡蛋
        if(this.techFlag === 3){
            getGameObjectById('hand').getBehaviour(Transform).x = 850
            getGameObjectById('hand').getBehaviour(Transform).y = 400

        }
        //铲er
        if(this.techFlag === 4){
            getGameObjectById('hand').getBehaviour(Transform).x = 550
            getGameObjectById('hand').getBehaviour(Transform).y = 450
            getGameObjectById('handMove').getBehaviour(Display).IsActive = true
        }
        //指向酱料
        if(this.techFlag === 5){
            getGameObjectById('hand').getBehaviour(Transform).x = 550
            getGameObjectById('hand').getBehaviour(Transform).y = 200

        }
        //指向肠
        if(this.techFlag === 6){
            getGameObjectById('hand').getBehaviour(Transform).x = 800
            getGameObjectById('hand').getBehaviour(Transform).y = 250

        }
        //指向铲子【收】
        if(this.techFlag === 7){
            getGameObjectById('hand').getBehaviour(Transform).x = 700
            getGameObjectById('hand').getBehaviour(Transform).y = 450

        }
        //指向盒子
        if(this.techFlag === 8){
            getGameObjectById('hand').getBehaviour(Transform).x = 180
            getGameObjectById('hand').getBehaviour(Transform).y = 100

        }
        
    }
    onTick(duringTime: number) {
        // const transform = this.gameObject.getBehaviour(Transform);
        // transform.x += this.currentSpeed;
        //跳转场景
        let i = getGameObjectById("fullpackage").getBehaviour(AnimationRenderer).currentFrame
        let a = getGameObjectById("fullpackageBJUT").getBehaviour(AnimationRenderer).currentFrame
        if(i === 8){
            this.engine.scenenumber = 3
            getGameObjectById('fullpackage').getBehaviour(AnimationRenderer).currentFrame = 0;
            getGameObjectById('fullpackage').getBehaviour(Display).IsActive = false
            
        }
        if(a === 8){
            this.engine.scenenumber = 3
            getGameObjectById('UI_dialog_button_what').getBehaviour(OrderButtonClick).what_clickFlag=0;
            getGameObjectById('fullpackageBJUT').getBehaviour(AnimationRenderer).currentFrame = 0;
            getGameObjectById('fullpackageBJUT').getBehaviour(Display).IsActive = false
            
        }

    }
}

